//
//  ScoreAndTimeLayer.cpp
//  CanYouDoIt
//
//  Created by hoangtx on 7/6/13.
//
//

#include "ScoreAndTimeLayer.h"
#include "MyUtilities.h"
#include "StaticVariables.h"
bool ScoreAndTimeLayer::init(){
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    scoreLabel = CCLabelBMFont::create("S: 0", "Info.fnt");
    scoreLabel->setAnchorPoint(ccp(0.5,1));
    scoreLabel->setPosition(ccp(winSize.width/4,winSize.height));
    scoreLabel->setScale((getBarHeight())/scoreLabel->getContentSize().height);
    //scoreLabel->setColor(ccc3(0,0,0));
    this->addChild(scoreLabel);
    
    timeLabel = CCLabelBMFont::create("T: 0", "Info.fnt");
    timeLabel->setAnchorPoint(ccp(0.5,1));
    timeLabel->setPosition(ccp(winSize.width*3/4,winSize.height));
    timeLabel->setScale(scoreLabel->getScale());
    //timeLabel->setColor(ccc3(200,0,0));
    this->addChild(timeLabel);
    return true;
}

void ScoreAndTimeLayer::turnToType(int mGameType){
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    gameType = mGameType;
    switch (gameType) {
        case GAME_COUNT_DOWN:{
            
        }
            break;
            
        case GAME_COUNT_TIME:{
            scoreLabel->setVisible(false);
            timeLabel->setPosition(ccp(winSize.width/2,winSize.height));
        }
            break;
    }
}

double ScoreAndTimeLayer::getBarHeight(){
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    return winSize.width*0.1f;
}
CCRect ScoreAndTimeLayer::getBarRect(){
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    double height = getBarHeight();
    return CCRectMake(0, winSize.height-height, winSize.width, height);
}


void ScoreAndTimeLayer::updateScore(int score){
    std::string scoreString ="S: ";
    scoreString+=MyUtilities::toString(score);
    scoreLabel->setString(scoreString.c_str());
}
void ScoreAndTimeLayer::updateTime(int time){
    std::string timeString ="T: ";
    timeString+=MyUtilities::toString(time);
    timeLabel->setString(timeString.c_str());
}

void ScoreAndTimeLayer::draw(){
    CCLayer::draw();
    
    //MyUtilities::drawRectAndFillWithColor(getBarRect(), ccc4(255,255,255,255));
    
    glLineWidth(getBarHeight()*0.1f);
    ccDrawColor4B(255, 255, 255, 255);
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    //vertical
    if(gameType == GAME_COUNT_DOWN){
    ccDrawLine(ccp(winSize.width/2,winSize.height), ccp(winSize.width/2,winSize.height-getBarHeight()));
    }
    //horizontal
    ccDrawLine(ccp(0,winSize.height-getBarHeight()), ccp(winSize.width,winSize.height-getBarHeight()));
}